package com.example.presentshopping.ui.custom

import android.content.Context
import android.graphics.PorterDuff
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import android.view.View.OnTouchListener
import androidx.appcompat.widget.AppCompatButton

class SelectedButton(context: Context?, attrs: AttributeSet?) : AppCompatButton(
    context!!, attrs
), OnTouchListener {
    override fun onTouch(v: View, event: MotionEvent): Boolean {
        val drawable = this.background
        when (event.action) {
            MotionEvent.ACTION_DOWN -> {
                drawable.setColorFilter(-0x131314, PorterDuff.Mode.MULTIPLY)
                setBackgroundDrawable(drawable)
            }
            MotionEvent.ACTION_UP -> drawable.clearColorFilter()
        }
        return false
    }

    init {
        setOnTouchListener(this)
    }
}